package org.hu.flexeasy.components
{
	import flash.display.CapsStyle;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.LineScaleMode;
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.core.UIComponent;
	
	import org.hu.flexeasy.util.Utils;
	
	import spark.components.Group;
	import spark.components.HGroup;

	public class HContainer extends HGroup
	{
		private var loadMasks:LoadMasks;
		
		private var _loadIdentification:Boolean = true;
		
		public function HContainer()
		{
			super();
		}

		public var borderSides:String="all";
		public var backgroupColor:uint = 0;
		public var borderColor:uint = 0xB5B8C8;		
		
		private var _textAlign:String = "center";
		
		override protected function createChildren():void
		{
			super.createChildren();
			
			if(!loadMasks && loadIdentification)
			{
				loadMasks = new LoadMasks;
				this.addElement(loadMasks);						
//				this.addElementAt(loadMasks,this.numElements);						
			}
		}
		
		override protected function updateDisplayList(w:Number, h:Number):void
		{
			super.updateDisplayList(w, h);
			
			var g:Graphics=graphics;
			if (isNaN(w) || isNaN(h))
				return;
			g.clear();

			Utils.drawBackgroup(backgroupColor,g,w,h);			
			g.lineStyle(1, borderColor);
			Utils.drawBorder(Utils.lineSides(borderSides),g,w,h);
			
			if(loadMasks)
			{
				loadMasks.width = w;
				loadMasks.height = h;
				
				loadMasks.x = 0;
				loadMasks.y = 0;
				
				loadMasks.includeInLayout = false;				
			}						
		}
		
		/**
		 * 启用加载
		 */
		public function startUsing():void
		{
			//this.stage.frameRate = 12;
			this.setLoadStatus(true);
		}
		
		/**
		 * 结束加载
		 */
		public function finishUsing():void
		{ 
			//this.stage.frameRate = 24;
			this.setLoadStatus(false);
		}
		
		private function setLoadStatus(status:Boolean):void
		{
			if(loadMasks && loadMasks.visible != status)
			{
				loadMasks.visible = status;
			}
		}
		
		public function get textAlign():String
		{
			return _textAlign;
		}

		public function set textAlign(value:String):void
		{
			_textAlign = value;
		}

		/**
		 * 创建容器时，是否创建加载等待提示内容
		 */
		public function get loadIdentification():Boolean
		{
			return _loadIdentification;
		}

		/**
		 * @private
		 */
		public function set loadIdentification(value:Boolean):void
		{
			_loadIdentification = value;
		}		
	}
}